//
//  TypeView.m
//  QuickCure
//
//  Created by 王震 on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "TypeView.h"
#import "OneTypeView.h"

@implementation TypeView

-(instancetype)init{
    if (self = [super init]) {
        [self creatSubViews];
    }
    return self;
}

#define kMargin 1
#define kCount 3

-(void)creatSubViews
{
//    NSArray *titleArr = @[@"肿瘤",@"心血管",@"神经病",@"血液科",@"骨科",@"公益"];
//    NSArray *titleImageArr = @[@"zl",@"xyg",@"sj",@"xy",@"gt",@"gy"];
    NSArray *titleArr = @[@"肿瘤",@"血液科",@"心血管",@"神经病",@"骨科",@"公益"];
    NSArray *titleImageArr = @[@"zl",@"xy",@"xyg",@"sj",@"gt",@"gy"];
    for (int i = 0; i < titleArr.count; i++) {
        NSString *titleStr = titleArr[i];
        UIImage *titleImage = [UIImage imageNamed:titleImageArr[i]];

        OneTypeView *typeView = [OneTypeView oneTypeViewWithTitle:titleStr image:titleImage];
        typeView.tag = i;
        [self addSubview:typeView];
    }
}
-(void)layoutSubviews{
    
    
    self.backgroundColor = [UIColor grayColor];
    
    
    
    CGSize kSize = [UIScreen mainScreen].bounds.size;
    
    CGFloat margin = kMargin;
    CGFloat kWidth = (kSize.width - (kCount + 1) * margin) / kCount;
    CGFloat kHeight = self.bounds.size.height * 0.5;
    
    [self.subviews enumerateObjectsUsingBlock:^(__kindof OneTypeView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSInteger row = idx % kCount;
        NSInteger col = idx / kCount;
        
        CGFloat X = margin + (kWidth + margin) * row;
        CGFloat Y = margin + (kHeight + margin) * col;
        
        
        obj.frame = CGRectMake(X, Y, kWidth, kHeight);
        
    }];
    //
    //    for (int i = 0; i < titleArr.count; i ++) {
    //
    //        NSInteger row = i % kCount;
    //        NSInteger col = i / kCount;
    //
    //        CGFloat X = margin + (kWidth + margin) * row;
    //        CGFloat Y = margin + (kHeight + margin) * col;
    //
    //
    //        typeView.frame = CGRectMake(X, Y, kWidth, kHeight);
    //       
    //        
    //    }
    
}


@end
